﻿//Create By Utopia 2020/09/16
using System.Collections.Generic;
using System.Data;
using DBCore.DB;

namespace DBCore
{
    public interface IBLL<T> 
    {   //實體----既是Class對象的實例化
        /// <summary>
        /// 數據庫添加實體
        /// </summary>
        /// <param name="model">實體</param>
        /// <returns></returns>
        int Add(T model);
        /// <summary>
        /// 數據庫更新實體
        /// </summary>
        /// <param name="model">實體</param>
        /// <returns></returns>

        int AddRange(List<T> model);
        /// <summary>
        /// 數據庫更新實體
        /// </summary>
        /// <param name="model">實體</param>
        /// <returns></returns>
        int Update(T model);
        /// <summary>
        /// 根數實體刪除數據
        /// </summary>
        /// <param name="model">實體</param>
        /// <returns></returns>
        int DeleteByModel(T model);
        /// <summary>
        /// 根據Key刪除數據
        /// </summary>
        /// <param name="key">對應數據表的Key值，本系統一般採用unid</param>
        /// <returns></returns>
        int DeleteByKey(object key);
        /// <summary>
        /// 根據Key的集合批量刪除數據---使用的是SQL中的In
        /// </summary>
        /// <param name="keys">key值集合</param>
        /// <returns></returns>
        int DeleteByIds(object[] keys);
        /// <summary>
        /// 根據where條件刪除數據
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        int DeleteByWhere(string where);

        /// <summary>
        /// 根據where條件獲取Count數
        /// </summary>
        /// <param name="where">where條件 example: "unid=''"</param>
        /// <returns></returns>
        int GetCount(string where);

        /// <summary>
        /// 根據Key值判別是否存在
        /// </summary>
        /// <param name="key">key值</param>
        /// <returns></returns>
        bool ExistsByKey(object key);
        /// <summary>
        /// 根據where條件判別數據是否存在
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        bool ExistsByWhere(string where);
        /// <summary>
        /// 判別該條數據是否存在，並返回這個Key值
        /// </summary>
        /// <param name="column">列</param>
        /// <param name="value">名</param>
        /// <param name="key">unid</param>
        /// <returns></returns>
        bool ExistsByColumnOutKey(string column, string value, out object key);
        /// <summary>
        /// 獲取實體數據Bykey
        /// </summary>
        /// <param name="key">unid的值</param>
        /// <returns></returns>
        T GetDetailByKey(object key);
        /// <summary>
        /// 通過TableRow 裡面的數據來獲取一個實體對象
        /// </summary>
        /// <param name="row">dataRow</param>
        /// <returns></returns>
        T GetModelByDataRow(DataRow row);
        /// <summary>
        /// 根據Where 條件獲取實體
        /// </summary>
        /// <param name="where">where條件</param>
        /// <returns></returns>
        List<T> GetListByWhere(string where);
        /// <summary>
        /// 獲取整張表的DataSet
        /// </summary>
        /// <returns></returns>
        /// 
        DataSet GetDataSet();
        /// <summary>
        /// 根據賽選條件獲取滿足條件的所有的值
        /// </summary>
        /// <param name="where">where條件</param>
        /// <returns></returns>
        DataSet GetDataSetByWhere(string where);
        /// <summary>
        /// 根據Where條件獲取對應Column的值
        /// </summary>
        /// <param name="where">where條件</param>
        /// <param name="columns">要獲取對應列的值---多列之間用","號隔開</param>
        /// <returns></returns>
        DataSet GetDataSetByWhereColumns(string where, string columns);
        /// <summary>
        /// 根據Where條件獲取前幾列數據
        /// </summary>
        /// <param name="topn">前幾列</param>
        /// <param name="columns"></param>
        /// <param name="where"></param>
        /// <param name="ordreby"></param>
        /// <returns></returns>
        DataSet GetDataSetByWhereOrderBy(int topn, string columns, string where, string ordreby);

        /// <summary>
        /// 獲取數據及By Group
        /// </summary>
        /// <param name="columns">列名</param>
        /// <param name="groupby">通過哪一列分組</param>
        /// <param name="ordreby">通過哪一列排序</param>
        /// <param name="topn">取前幾條數據</param>
        /// <param name="where">where 條件</param>
        /// <returns></returns>
        DataSet GetDataSetByGroup(int topn, string columns, string where, string orderby, string groupby);
        /// <summary>
        /// 獲取想要的數據不需要Where條件
        /// </summary>
        /// <param name="columns">列名</param>
        /// <param name="groupby">分組</param>
        /// <param name="ordreby">根據什麼排序</param>
        /// <param name="topn">前多少條</param>
        /// <returns></returns>
        DataSet GetDataSetByGroup(int topn,string columns, string groupby, string ordreby);
        /// <summary>
        /// 獲取數據不需要前多少條
        /// </summary>
        /// <param name="columns">列名</param>
        /// <param name="groupby">根據哪一列分組（列名）</param>
        /// <param name="ordreby">根據哪一列排序（列名）</param>
        /// <returns></returns>
        DataSet GetDataSetByGroup(string columns, string groupby, string ordreby);
        /// <summary>
        /// 獲取數據不需要排序
        /// </summary>
        /// <param name="columns">列名</param>
        /// <param name="groupby">根據什麼分組</param>
        /// <returns></returns>
        DataSet GetDataSetByGroup(string columns, string groupby);
        /// <summary>
        /// 鏈錶查詢---當前實體的表與需要鏈錶查詢的表
        /// </summary>
        /// <param name="topn">前多少條</param>
        /// <param name="columns">列名</param>
        /// <param name="tablename">表名</param>
        /// <param name="where">where條件</param>
        /// <param name="ordreby">通過什麼排序</param>
        /// <returns></returns>
        DataSet GetJoinDataSet(int topn, string columns, string where, string orderby, string JoinTableName, string on);
        /// <summary>
        /// 分頁獲取DataSet
        /// </summary>
        /// <param name="page">頁碼</param>
        /// <param name="pagesize">頁大小</param>
        /// <returns></returns>
        KeyValuePair<DataSet, int> GetPageDateSet(int page, int pagesize);
        /// <summary>
        /// where 條件進行分頁獲取
        /// </summary>
        /// <param name="page">頁碼</param>
        /// <param name="pagesize">頁大小</param>
        /// <param name="where">where條件</param>
        /// <returns></returns>
        KeyValuePair<DataSet, int> GetPageDateSet(int page, int pagesize, string where);
        /// <summary>
        /// 根據 分頁獲取對應列的數據
        /// </summary>
        /// <param name="page">頁碼</param>
        /// <param name="pagesize">頁大小</param>
        /// <param name="where">where條件</param>
        /// <param name="columns">列名</param>
        /// <returns></returns>
        KeyValuePair<DataSet, int> GetPageDateSet(int page, int pagesize, string where, string columns);
        /// <summary>
        /// 根據where 條件獲取數據集
        /// </summary>
        /// <param name="page">頁碼</param>
        /// <param name="pagesize">頁大小</param>
        /// <param name="where">where條件</param>
        /// <param name="columns">列名</param>
        /// <param name="ordreby">根據什麼排序</param>
        /// <returns></returns>
        KeyValuePair<DataSet, int> GetPageDateSet(int page, int pagesize, string where, string columns, string ordreby);
        /// <summary>
        /// 根據Where條件獲取鏈錶分頁
        /// </summary>
        /// <param name="page">頁碼</param>
        /// <param name="pagesize">頁大小</param>
        /// <param name="columns">列名</param>
        /// <param name="tablename">鏈錶的表名</param>
        /// <param name="where">where條件</param>
        /// <param name="ordreby">根據哪一列排序</param>
        /// <returns></returns>
        KeyValuePair<DataSet, int> GetJoinPageDateSet(int page, int pagesize, string columns, string tablename, string where, string ordreby,string on);
    }

    public interface IBLL
    {
        int Add(Entity model);

        int AddRange(Entity model);
        int Update(Entity model);
        int Del(Entity model);
        int Del(object key);
        int Del(object[] keys);
        int Del(string where);
        int Count(string where);

        bool Exists(object key);
        bool Exists(string where);
        bool Exists(string column, string value);
        bool Exists(string column, string value, out object key);
        bool Exists(string column, string value, object key);

        Entity GetDetailByKey(object key);
        Entity GetModelByDataRow(DataRow row);

        DataSet GetDataSet();
        DataSet GetDataSet(string where);
        DataSet GetDataSet(string where, string columns);
        DataSet GetDataSet(int topn, string columns, string where, string ordreby);
        DataSet GetDataSetByGroup(string columns, string groupby, string ordreby, int topn, string where);
        DataSet GetDataSetByGroup(string columns, string groupby, string ordreby, int topn);
        DataSet GetDataSetByGroup(string columns, string groupby, string ordreby);
        DataSet GetDataSetByGroup(string columns, string groupby);
        DataSet GetJoinDataSet(int topn, string columns, string where, string orderby, string JoinTableName, string on);
        KeyValuePair<DataSet, int> GetPageDateSet(int page, int pagesize);
        KeyValuePair<DataSet, int> GetPageDateSet(int page, int pagesize, string where);
        KeyValuePair<DataSet, int> GetPageDateSet(int page, int pagesize, string where, string columns);
        KeyValuePair<DataSet, int> GetPageDateSet(int page, int pagesize, string where, string columns, string ordreby);
        KeyValuePair<DataSet, int> GetJoinPageDateSet(int page, int pagesize, string columns, string tablename, string where, string ordreby,string on);
    }
}
